//
//  HXHelpSupportViewController.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/23.
//

#import "HXHelpSupportViewController.h"
#import "WKWebViewController.h"

@interface HXHelpSupportViewController ()

@end

@implementation HXHelpSupportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    self.fd_prefersNavigationBarHidden = YES;
    [self BottomFunction];
}

-(void)BottomFunction{
    
    UIImageView *tabr = [[UIImageView alloc] initWithFrame:CGRectMake(0, kNavHeight-44, winWidth, 44)];
    [self.view addSubview:tabr];
    UIImageView *mainscreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, winWidth, 44)];
    if([themeColors isEqualToString:@"default"]){
        mainscreen.image = [UIImage imageNamed:@"helpmain"];
        
    }else{
        mainscreen.image = [UIImage imageNamed:@"helpmid"]; 
    }
    [tabr addSubview:mainscreen];
    [self addSelectCorrespondence];
    
    UIImageView *statebj = [[UIImageView alloc] init];
    if([themeColors isEqualToString:@"default"]){
        statebj.backgroundColor = [UIColor blackColor];
    }else{
        statebj.backgroundColor = midnightRGB;
    }
    [self.view addSubview:statebj];
    [statebj mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-34);
        make.height.mas_equalTo(50);
    }];
#pragma mark 返回入口
    UIImageView *backview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back"]];
    backview.userInteractionEnabled = YES;
    [self.view addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-37);
        make.width.mas_equalTo(33);
        make.height.mas_equalTo(36);
        make.left.mas_equalTo(26);
    }];
    
    UIButton *backbt = [UIButton buttonWithType:UIButtonTypeCustom];
    [backbt addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backview addSubview:backbt];
    [backbt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(backview);
    }];
    
    UIImageView *checkbox =[[UIImageView alloc] init];
    if([themeColors isEqualToString:@"default"]){
        checkbox.image = [UIImage imageNamed:@"checkbox"];
        checkbox.backgroundColor = [UIColor blackColor];
        
    }else{
        checkbox.image = [UIImage imageNamed:@""];
        checkbox.backgroundColor = midnightRGB;
        checkbox.layer.cornerRadius = 8;
        checkbox.layer.masksToBounds = YES;
    }
//    checkbox.image = [UIImage imageNamed:@"checkbox"];
    checkbox.userInteractionEnabled = YES;
    [self.view addSubview:checkbox];
    [checkbox mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(backview.mas_top).offset(-43.33);
        make.width.mas_equalTo(315);
        make.height.mas_equalTo(47);
        make.centerX.mas_equalTo(self.view);
    }];
    UIImageView *feefback = [[UIImageView alloc] init];
    feefback.image = [UIImage imageNamed:@"feefback"];
    [checkbox addSubview:feefback];
    [feefback mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(13);
        make.left.mas_equalTo(19);
        make.width.mas_equalTo(20.33);
        make.height.mas_equalTo(20.67);
    }];
    
    UIImageView *feefbackname = [[UIImageView alloc] init];
    feefbackname.image = [UIImage imageNamed:@"feefbackname"];
    [checkbox addSubview:feefbackname];
    [feefbackname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(13);
        make.left.mas_equalTo(feefback.mas_right).offset(13.33);
        make.width.mas_equalTo(100.33);
        make.height.mas_equalTo(17.33);
    }];
    
    
    UIImageView *subordinate = [[UIImageView alloc] init];
    subordinate.image = [UIImage imageNamed:@"subordinate"];
    [checkbox addSubview:subordinate];
    [subordinate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(14.3);
        make.width.mas_equalTo(18.67);
        make.height.mas_equalTo(21);
    }];
    
    UIButton *feedbackbt = [UIButton buttonWithType:UIButtonTypeCustom];
    feedbackbt.tag = 5;
    [feedbackbt addTarget:self action:@selector(selectCorrespondence:) forControlEvents:UIControlEventTouchUpInside];
    [checkbox addSubview:feedbackbt];
    [feedbackbt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(checkbox);
    }];
    
//    feedbackexplain
    UIImageView *feedbackexplain = [[UIImageView alloc] init];
    feedbackexplain.image = [UIImage imageNamed:@"feedbackexplain"];
    [self.view addSubview:feedbackexplain];
    [feedbackexplain mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(checkbox.mas_top).offset(-10);
        make.width.mas_equalTo(320);
        make.height.mas_equalTo(36.67);
        make.centerX.mas_equalTo(self.view);
    }];
    
    UIImageView *bluetherview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluether"]];
    bluetherview.userInteractionEnabled = YES;
    [self.view addSubview:bluetherview];
    [bluetherview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-52);
        make.height.mas_equalTo(13);
    }];
    
}
-(void)addSelectCorrespondence{
    
    //    subordinate箭头
    NSArray *viewarray = @[@"heipsupport",@"update",@"forum",@"fbgroup",@"feefback"];
    NSArray *namearray = @[@"supportname",@"updatename",@"forumname",@"fbgroupname",@"aboutusname"];
    
    for (NSInteger i = 0; i < viewarray.count; i ++) {
        
        UIImageView *checkbox =[[UIImageView alloc] init];
        if([themeColors isEqualToString:@"default"]){
//            mainscreen.image = [UIImage imageNamed:@"mainscreen"];
            checkbox.image = [UIImage imageNamed:@"checkbox"];
        }else{
            checkbox.layer.cornerRadius = 8;
            checkbox.layer.masksToBounds = YES;
            checkbox.backgroundColor = midnightRGB;
        }
//        checkbox.image = [UIImage imageNamed:@"checkbox"];
        
        checkbox.userInteractionEnabled = YES;
        checkbox.frame = CGRectMake((winWidth-315)/2, 53+kNavHeight+i*(11.6+47), 315, 47);
        [self.view addSubview:checkbox];
        
        UIButton *checkboxbt = [UIButton buttonWithType:UIButtonTypeCustom];
        checkboxbt.frame = CGRectMake(0, 0, 315, 47);
        checkboxbt.tag = i;
        [checkboxbt addTarget:self action:@selector(selectCorrespondence:) forControlEvents:UIControlEventTouchUpInside];
        [checkbox addSubview:checkboxbt];
        
        UIImageView *subordinate = [[UIImageView alloc] init];
        subordinate.frame = CGRectMake(315-36, 12.6, 20.33, 20.33);
        subordinate.image = [UIImage imageNamed:@"network"];
        [checkbox addSubview:subordinate];
        
        UIImageView *arrayview = [[UIImageView alloc] init];
        arrayview.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",viewarray[i]]];
        
        UIImageView *name = [[UIImageView alloc] init];
        name.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",namearray[i]]];
        
        switch (i) {
            case 0:
                arrayview.frame = CGRectMake(19, 13, 20.67, 20.67);
                name.frame = CGRectMake(19+20.67+13.3, 14.3, 87, 21.33);
                break;
            case 1:
                arrayview.frame = CGRectMake(19, 13, 20.67, 20.67);
                name.frame = CGRectMake(19+20.67+13.3, 14.3, 75, 21);
                break;
            case 2:
                arrayview.frame = CGRectMake(19, 13, 20.67, 20.67);
                name.frame = CGRectMake(19+20.67+13.3, 14.3, 63, 17);
                break;
            case 3:
                arrayview.frame = CGRectMake(19, 13, 20.33, 20.33);
                name.frame = CGRectMake(19+20.33+13.3, 14.3, 100, 21.33);
                break;
            case 4:
                arrayview.frame = CGRectMake(19, 13, 21.67, 20.33);
                name.frame = CGRectMake(19+20.33+12.67, 14.3, 100, 17.67);
                break;
                
            default:
                break;
                
        }
        [checkbox addSubview:name];
        [checkbox addSubview:arrayview];
    }
    
    
    
}
-(void)selectCorrespondence:(UIButton *)button{
    
    NSLog(@"点击了对应按钮%ld",(long)button.tag);
    switch (button.tag) {
        case 5:
            [self jumpFeedBack];
            break;
        case 4:
            [self jumpaboutus];
            break;
        case 1:
            [self update];
            break;
        case 3:
            [self fbgroup];
            break;
        case 2:
            [self forum];
            break;
        case 0:
            [self heipsupport];
            break;
        default:
            break;
    }
}
- (void)jumpaboutus{
    WKWebViewController *web = [[WKWebViewController alloc] init];
    [web loadWebURLSring:@"https://www.bluethermagic.com/pages/bluether-design"];
    [self.navigationController pushViewController:web animated:YES];
}
- (void)heipsupport{
    
//https://www.bluethermagic.com/pages/faqs
    WKWebViewController *web = [[WKWebViewController alloc] init];
    [web loadWebURLSring:@"https://www.bluethermagic.com/pages/faqs"];
    [self.navigationController pushViewController:web animated:YES];
}
- (void)forum{
    
    WKWebViewController *web = [[WKWebViewController alloc] init];
    [web loadWebURLSring:@"https://www.bluethermagic.com/pages/review"];
    [self.navigationController pushViewController:web animated:YES];
}
- (void)update{
    
//    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"It's the latest version" message:@"" preferredStyle:UIAlertControllerStyleAlert];
//
//    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
////        [self installAppWithModel:model];
//        NSLog(@"点击了yes");
//    }];
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//
//    }];
//    [alertVc addAction:sureAction];
//    [alertVc addAction:cancelAction];
//    [self presentViewController:alertVc animated:YES completion:nil];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://apps.apple.com/us/app/bluether/id6469992349"]];

}
- (void)fbgroup{
    
//    NSURL *facebookURL = [NSURL URLWithString:@"fb://profile/113810631976867"];
//https://www.facebook.com/Iarvelmagic
    NSURL *facebookURL = [NSURL URLWithString:@"https://www.facebook.com/Iarvelmagic"];
    if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
        [[UIApplication sharedApplication] openURL:facebookURL];
    } else {
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://facebook.com"]];
//    https://www.facebook.com/Iarvelmagic
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/Iarvelmagic"]];
    }
}
-(void)jumpFeedBack{

//    HXHelpSupportViewController
    HXFeedBackViewController*jum = [[HXFeedBackViewController alloc] init];
    jum.modalPresentationStyle = NSDateFormatterNoStyle;
//    [self presentViewController:jum animated:YES completion:nil];
    [self.navigationController pushViewController:jum animated:YES];
}
-(void)back{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
